home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.pl1,comp.lang.c
- Subject: Re: PL/I and C
- Date: 27 Feb 1996 18:04:28 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4h066c$r0t@solutions.solon.com>
- References: <4gh5ru$eng@goanna.cs.rmit.EDU.AU> <4grhtv$s31@goanna.cs.rmit.EDU.AU> <4gt0tv$826@solutions.solon.com> <4gv8h0$3o2k@news-s01.ny.us.ibm.net>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4gv8h0$3o2k@news-s01.ny.us.ibm.net>,
- <Chris_harlow@artemis-intl.com> wrote:
- >In <4gt0tv$826@solutions.solon.com>, seebs@solutions.solon.com (Peter Seebach) writes:
- >>Yes, C's string handling is primitive. It also has no hidden overhead.
-
- >I'm sure you know C better than me but I know enough C to refute your
- >statement... for example:
-
- >(1) The PL/1 equivalent of strlen() requires only a single load instruction.
- > Wheres the 'hidden overhead'... you guessed it, its in the C library!
-
- No, that's not hidden overhead. That's *obvious* overhead. Contrast PL/I's
- string >= otherstring
- (not sure what the punctuation is). Looks like a trivial operation, generates
- nontrival code. (Sort of like the hidden overhead of structure assignment
- in C.)
-
- >(2) My processor has a move-n-bytes instruction.
- > When I assign a string to a string in PL/1 the compiler knows in advance
- > WITHOUT OVERHEAD how many bytes it is going to have to move and simply
- > generates the required single instruction. (even on cpus without move-n-bytes
- > instructions, I have seen PL/1 generated code that performed 4-byte move
- > instructions or load/stores until it was within 3 bytes of the end of the string..
- > this is far more intelligent than having to check every byte for null..)
-
- Yes, and is a fair trade-off if you want fixed-length strings. C will let
- you produce objects which act sort of like strings but are fixed in length,
- and do the righ ops with them. It generally isn't worth it.
-
- Meanwhile, many modern C compilers have built-ins for all of the library
- functions, and do similar tricks for copying and moving strings.
-
- > Many have pointed out that C is rather lower level than PL/1 and I dont think
- > anyone would disagree. My point is that the C language is sometimes at a
- > lower level than my processors machine code... this puts extra load in the
- > C string library...
-
- On the other hand, I've seen a *portable* C implementation of strfoo()
- outperform the single-instruction way to do it on the Pentium - because
- the C implementation was smarter than the P5. You don't have to use
- a feature just because it's there.
-
- > SO I think a better statement would have been:
- > Yes, C's string handling is primitive AND it contains hidden overhead.
-
- No, just overhead. None of it's hidden.
-
- Are you telling me PL/I can't have a non-fixed length string, dynamically
- allocated? If it can, the compare or copy functionality will do the same
- thing strcmp() and strcpy() do at some level. If it can't, it sucks. (Well,
- not really, but this is a language war, we have to say *something* rude.)
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-